package xyz.heyaoshare.core.controller.system.user;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
import xyz.heyaoshare.annotation.OperationLog;
import xyz.heyaoshare.common.entity.bo.Result;
import xyz.heyaoshare.common.entity.bo.ResultPage;
import xyz.heyaoshare.core.controller.system.user.vo.req.*;
import xyz.heyaoshare.core.controller.system.user.vo.resp.UserDetailRespVO;
import xyz.heyaoshare.core.controller.system.user.vo.resp.UserInfoRespVO;
import xyz.heyaoshare.core.controller.system.user.vo.resp.UserListRespVO;
import xyz.heyaoshare.core.controller.system.user.vo.resp.UserPageRespVO;
import xyz.heyaoshare.core.service.system.UserService;

import java.util.List;
import java.util.Set;

import static xyz.heyaoshare.common.constants.VersionManager.V001;

/**
 * 用户相关
 * @author YueHe
 * @version 0.0.1
 * @since 2025/5/9 下午1:50
 */
@RestController
@RequestMapping(V001 + "/system/user")
@Tag(name = "用户相关")
public class UserController {

    @Resource
    private UserService userService;

    @OperationLog
    @GetMapping("page")
    @Operation(summary = "用户分页")
    public Result<ResultPage<UserPageRespVO>> selectPage(@ParameterObject @Valid UserPageReqVO reqVO) {
        ResultPage<UserPageRespVO> items = userService.selectPage(reqVO);
        return Result.ok(items);
    }

    @OperationLog
    @GetMapping("list")
    @Operation(summary = "用户列表")
    public Result<List<UserListRespVO>> selectList(@ParameterObject @Valid UserListReqVO reqVO) {
        List<UserListRespVO> items = userService.selectList(reqVO);
        return Result.ok(items);
    }

    @OperationLog
    @GetMapping("detail")
    @Operation(summary = "用户详情")
    public Result<UserDetailRespVO> selectDetail(@ParameterObject @Valid UserDetailReqVO reqVO) {
        UserDetailRespVO item = userService.selectDetail(reqVO);
        return Result.ok(item);
    }

    @OperationLog
    @GetMapping("getUserInfo")
    @Operation(summary = "用户信息", description = "登录成功后调用此接口获取用户信息")
    public Result<UserInfoRespVO> getUserInfo() {
        UserInfoRespVO item = userService.getUserInfo();
        return Result.ok(item);
    }

    @OperationLog
    @GetMapping("getPermissions")
    @Operation(summary = "用户权限信息", description = "登录成功后调用此接口获取用户权限信息")
    public Result<Set<String>> getPermissions() {
        Set<String> item = userService.getPermissions();
        return Result.ok(item);
    }

    @OperationLog
    @PostMapping("insert")
    @Operation(summary = "新增用户")
    public Result<Boolean> insert(@RequestBody @Valid UserInsertReqVO reqVO) {
        Boolean status = userService.insert(reqVO);
        return Result.ok(status);
    }

    @OperationLog
    @DeleteMapping("delete")
    @Operation(summary = "删除用户", description = "目前不允许删除用户", hidden = true)
    public Result<Boolean> delete(@RequestBody @Valid UserDeleteReqVO reqVO) {
        Boolean status = userService.delete(reqVO);
        return Result.ok(status);
    }

    @OperationLog
    @PutMapping("update")
    @Operation(summary = "更新用户")
    public Result<Boolean> updateData(@RequestBody @Valid UserUpdateReqVO reqVO) {
        Boolean status = userService.updateData(reqVO);
        return Result.ok(status);
    }

}